/**
 * 初始化系统参数详情对话框
 */
var TimeInfoInfoDlg = {
    timeInfoInfoData : {},
    validateFields: {
        name: {
            validators: {
                notEmpty: {
                    message: '时段名称不能为空'
                }
            }
        }
    }
};
/**
 * 验证数据是否为空
 */
TimeInfoInfoDlg.validate = function () {
    $('#timeInfoForm').data("bootstrapValidator").resetForm();
    $('#timeInfoForm').bootstrapValidator('validate');
    return $("#timeInfoForm").data('bootstrapValidator').isValid();
}

/**
 * 清除数据
 */
TimeInfoInfoDlg.clearData = function() {
    this.timeInfoInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TimeInfoInfoDlg.set = function(key, val) {
    this.timeInfoInfoData[key] = (typeof val == "undefined") ? $("[id='"+key+"']").val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TimeInfoInfoDlg.get = function(key) {
    return $("[id='"+key+"']").val();
}

/**
 * 关闭此对话框
 */
TimeInfoInfoDlg.close = function() {
    parent.layer.close(window.parent.TimeInfo.layerIndex);
}

/**
 * 收集数据
 */
TimeInfoInfoDlg.collectData = function() {
    this
        .set('id')
        .set('version')
        .set('name')
        .set('sunTime1')
        .set('sunTime2')
        .set('sunTime3')
        .set('monTime1')
        .set('monTime2')
        .set('monTime3')
        .set('tueTime1')
        .set('tueTime2')
        .set('tueTime3')
        .set('wedTime1')
        .set('wedTime2')
        .set('wedTime3')
        .set('thuTime1')
        .set('thuTime2')
        .set('thuTime3')
        .set('friTime1')
        .set('friTime2')
        .set('friTime3')
        .set('satTime1')
        .set('satTime2')
        .set('satTime3')
    ;
}

/**
 * 提交添加
 */
TimeInfoInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/door/time/info/add", function(data){
        Feng.success("添加成功!");
        window.parent.TimeInfo.table.refresh();
        TimeInfoInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.timeInfoInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
TimeInfoInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/door/time/info/update", function (data) {
        Feng.success("修改成功!");
        window.parent.TimeInfo.table.refresh();
        TimeInfoInfoDlg.close();
    }, function (data) {
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.timeInfoInfoData);
    ajax.start();
}
// .set('sunTime1')
// .set('sunTime2')
// .set('sunTime3')
// .set('monTime1')
// .set('monTime2')
// .set('monTime3')
// .set('tueTime1')
// .set('tueTime2')
// .set('tueTime3')
// .set('wedTime1')
// .set('wedTime2')
// .set('wedTime3')
// .set('thuTime1')
// .set('thuTime2')
// .set('thuTime3')
// .set('friTime1')
// .set('friTime2')
// .set('friTime3')
// .set('satTime1')
// .set('satTime2')
// .set('satTime3')
$(function () {
    lay('.time-item').each(function(){
        laydate.render({
            elem: '#sunTime1'
            , type: 'time'
            , range: '~' //或 range: '~' 来自定义分割字符
            ,format: 'HH:mm'
        });
    });
    laydate.render({
        elem: '#sunTime1'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });
    laydate.render({
        elem: '#sunTime2'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });
    laydate.render({
        elem: '#sunTime3'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });

    laydate.render({
        elem: '#monTime1'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });
    laydate.render({
        elem: '#monTime2'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });
    laydate.render({
        elem: '#monTime3'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });

    laydate.render({
        elem: '#tueTime1'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });laydate.render({
        elem: '#tueTime2'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });laydate.render({
        elem: '#tueTime3'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });

    laydate.render({
        elem: '#wedTime1'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });laydate.render({
        elem: '#wedTime2'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });laydate.render({
        elem: '#wedTime3'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });

    laydate.render({
        elem: '#thuTime1'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });laydate.render({
        elem: '#thuTime2'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });laydate.render({
        elem: '#thuTime3'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });

    laydate.render({
        elem: '#friTime1'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });laydate.render({
        elem: '#friTime2'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });laydate.render({
        elem: '#friTime3'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });

    laydate.render({
        elem: '#satTime1'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });laydate.render({
        elem: '#satTime2'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });laydate.render({
        elem: '#satTime3'
        , type: 'time'
        , range: '~' //或 range: '~' 来自定义分割字符
        ,format: 'HH:mm'
    });
    Feng.initValidator("timeInfoForm", TimeInfoInfoDlg.validateFields);
});
